/*
Copyright (c) 2012, Weikexin eeplat.com
Released under the MIT license.
http://www.opensource.org/licenses/mit-license.php
 */
package com.eeplat.social.openapi.qq;

import com.eeplat.social.openapi.callback.GlobalConfig;
import com.eeplat.social.openapi.http.URIUtil;

public class URIUtilQQ implements URIUtil {

	public static final String QQ_BASE = "https://graph.qq.com/oauth2.0/";

	public static final String QQ_AUTH = "https://graph.qq.com/oauth2.0/authorize";

	public static final String QQ_TOKEN = "https://graph.qq.com/oauth2.0/token";

	public static final String QQ_GET_USER_INFO = "https://graph.qq.com/user/get_user_info";
	


	/* (non-Javadoc)
	 * @see com.eeplat.social.openapi.qq.BaseURIUtil#wrappRedirectUri()
	 */
	@Override
	public String wrappRedirectUri() {

		// https://graph.qq.com/oauth2.0/authorize?response_type=code&client_id=[YOUR_APPID]&redirect_uri=[YOUR_REDIRECT_URI]&scope=[THE_SCOPE]

		StringBuffer sb = new StringBuffer(QQ_AUTH);
		sb.append("?response_type=code&display=page&client_id=")
				.append(GlobalConfig.getValue("qq.appid"))
				.append("&redirect_uri=")
				.append(GlobalConfig.getValue("qq.cb"));
		return sb.toString();
	}

	/* (non-Javadoc)
	 * @see com.eeplat.social.openapi.qq.BaseURIUtil#wrappAuthCodeUri(java.lang.String)
	 */

	@Override
	public String wrappAuthCodeUri(String authCode) {

		StringBuffer sb = new StringBuffer(QQ_TOKEN);
		sb.append("?grant_type=authorization_code&client_id=")
				.append(GlobalConfig.getValue("qq.appid"))
				.append("&client_secret=")
				.append(GlobalConfig.getValue("qq.appkey")).append("&code=")
				.append(authCode).append("&state=").append("qq")
				.append("&redirect_uri=")
				.append(GlobalConfig.getValue("qq.cb"));
		return sb.toString();
	}

	/* (non-Javadoc)
	 * @see com.eeplat.social.openapi.qq.BaseURIUtil#wrappAccessTokenUri(java.lang.String)
	 */

	@Override
	public String wrappAccessTokenUri(String accessToken) {

		StringBuffer sb = new StringBuffer(QQ_BASE);
		sb.append("me?access_token=").append(accessToken);
		return sb.toString();
	}

	/* (non-Javadoc)
	 * @see com.eeplat.social.openapi.qq.BaseURIUtil#wrappGetUserInfoUri(java.lang.String, java.lang.String)
	 */

	@Override
	public String wrappGetUserInfoUri(String accessToken, String openid) {

		StringBuffer sb = new StringBuffer(QQ_GET_USER_INFO);
		sb.append("?access_token=").append(accessToken)
				.append("&oauth_consumer_key=")
				.append(GlobalConfig.getValue("qq.appid")).append("&openid=")
				.append(openid);
		return sb.toString();
	}

}
